<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath%>">
		<title>insert title</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">    
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
			<link rel="stylesheet" type="text/css" href="styles.css">
		-->
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui/css/H-ui.min.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/css/H-ui.admin.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/lib/Hui-iconfont/1.0.7/iconfont.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/lib/icheck/icheck.css" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/skin/default/skin.css" id="skin" />
		<link rel="stylesheet" type="text/css" href="<%=basePath %>scripts/static/h-ui.admin/css/style.css" />
		<script type="text/javascript" src="<%=basePath %>scripts/jquery-1.9.1.js"></script>
		<script type="text/javascript" src="<%=basePath %>scripts/lib/layer/2.1/layer.js"></script>
		<script type="text/javascript">
			window.onload=collegeInit();
			function collegeInit(){
				$.ajax({
					url:'<%=basePath%>major/json/loadCollege',
					type:'post',
					dataType:'json',
					success:function(data){
						var html="";
						$.each(data,function(i,val){
							html+="<option value='"+val.collegeNo+"'>"+val.coolegeName+"</option>";
						});
						$("#college").append(html);
						//alert(html);
					},
					error:function(){
						layer.msg("ajax error");
					}
				});
			}
			/*关闭layer窗口*/
			function layer_close(){
				window.parent.layer.closeAll();
			}
			/*添加学院信息*/
			function major_add(){
				var majorNo = $("input[name='majorNo']").val();
				var majorName = $("input[name='majorName']").val();
				var collegeNo = $("#college").val();
				$.ajax({
					url:'<%=basePath%>major/addMajor',
					type:'post',
					dataType:'text',
					data:{"college.collegeNo":collegeNo,"majorNo":majorNo,"majorName":majorName},
					success:function(text){
						if(text=="success"){
							layer.msg("添加成功",{icon:1, time:500});
							setTimeout(function(){
								window.parent.location.reload();
							}, 1000);
						}
					},
					error:function(){
						layer.msg("添加异常");
					}
				});
			}
		</script>
	</head>
	<body>
		<div class="page-container">
			
			<form class="form form-horizontal">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>所属学院：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<select id="college" class="select" name="collegeNo"></select>
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>专业编号：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" name="majorNo">
					</div>
				</div>
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>专业名称：</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="text" class="input-text" name="majorName">
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
						<button onClick="major_add()" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
						<button onClick="layer_close()" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
					</div>
				</div>
			</form>
		</div>
	</body>
</html>